package com.facebank.usersupport.controller;

import com.facebank.usersupport.model.DgutComment;
import com.facebank.usersupport.model.DgutNotes;
import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.service.INotesService;
import com.facebank.usersupport.util.ImgSaveUtil;
import com.facebank.usersupport.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
public class NotesController {
    @Autowired
    private INotesService notesService;

    /**
     * 添加游记
     *
     * @return
     */
    @RequestMapping(value = "/notes/add", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel add(String content, HttpSession session) {
        if (SessionUtil.getAssociatorId(session) == null || SessionUtil.getAssociatorId(session) == "") {
            return new RestModel("205", "用户没登录");
        }
        return notesService.add(content,session);
    }

    /**
     * 显示社区游记
     */
    @RequestMapping(value = "/notes/show", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel show() {
        return notesService.show();
    }

    /**
     * 显示个人游记
     */
    @RequestMapping(value = "/notes/person", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel person(HttpSession session) {
        if (SessionUtil.getAssociatorId(session) == null || SessionUtil.getAssociatorId(session) == "") {
            return new RestModel("205", "用户没登录");
        }
        Long assId = Long.valueOf(SessionUtil.getAssociatorId(session));
        return notesService.person(assId);
    }

    /**
     * 显示游记详情
     */
    @RequestMapping(value = "/notes/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel detail(Long notesId) {
        return notesService.detail(notesId);
    }

    /**
     * 发表评论
     */
    @RequestMapping(value = "/notes/add_comment", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel addComment(Long notesId,String content, HttpSession session) {
        if (SessionUtil.getAssociatorId(session) == null || SessionUtil.getAssociatorId(session) == "") {
            return new RestModel("205", "用户没登录");
        }
        Long assId = Long.valueOf(SessionUtil.getAssociatorId(session));
        DgutComment dgutComment = new DgutComment();
        dgutComment.setCommentTime(System.currentTimeMillis());
        dgutComment.setAssociatorId(assId);
        dgutComment.setContent(content);
        dgutComment.setNotesId(notesId);
        return notesService.addComment(dgutComment);
    }

    /**
     * 显示评论
     */
    @RequestMapping(value = "/notes/show_comment", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel showComment(Long notesId) {
        return notesService.showComment(notesId);
    }

    /**
     * 点赞实现
     */
    @RequestMapping(value = "/notes/like", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestModel like(Long notesId, HttpSession session) {
        if (SessionUtil.getAssociatorId(session) == null || SessionUtil.getAssociatorId(session) == "") {
            return new RestModel("205", "用户没登录");
        }
        return notesService.like(notesId, session);
    }

}
